/**
 * 
 */
package com.myBase.core.modules.goldcoinaccount.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.myBase.core.entity.GoldcoinAccount;
import com.myBase.core.facade.service.GoldcoinAccountServiceFacade;
import com.myBase.framework.common.config.Global;
import com.myBase.common.persistence.Page;
import com.myBase.framework.common.utils.StringUtils;
import com.myBase.framework.common.web.BaseController;

/**
 * ebei 系统用户账户信息Controller
 * @author WuJie
 * @version 2017-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/goldcoinaccount/goldcoinAccount")
public class GoldcoinAccountController extends BaseController {

    //@Autowired
    private GoldcoinAccountServiceFacade goldcoinAccountService;

    @ModelAttribute
    public GoldcoinAccount get(@RequestParam(required = false) String id) {
        GoldcoinAccount entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = goldcoinAccountService.get(id);
        }
        if (entity == null) {
            entity = new GoldcoinAccount();
        }
        return entity;
    }

    @RequiresPermissions("goldcoinaccount:goldcoinAccount:view")
    @RequestMapping(value = { "list", "" })
    public String list(GoldcoinAccount goldcoinAccount, HttpServletRequest request, HttpServletResponse response,
            Model model) {
        Page<GoldcoinAccount> page = goldcoinAccountService.findPage(new Page<GoldcoinAccount>(request, response),
                goldcoinAccount);
        model.addAttribute("page", page);
        return "modules/goldcoinaccount/goldcoinAccountList";
    }

    @RequiresPermissions("goldcoinaccount:goldcoinAccount:view")
    @RequestMapping(value = "form")
    public String form(GoldcoinAccount goldcoinAccount, Model model) {
        model.addAttribute("goldcoinAccount", goldcoinAccount);
        return "modules/goldcoinaccount/goldcoinAccountForm";
    }

    @RequiresPermissions("goldcoinaccount:goldcoinAccount:edit")
    @RequestMapping(value = "save")
    public String save(GoldcoinAccount goldcoinAccount, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, goldcoinAccount)) {
            return form(goldcoinAccount, model);
        }
        goldcoinAccountService.save(goldcoinAccount);
        addMessage(redirectAttributes, "保存金币账户成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinaccount/goldcoinAccount/?repage";
    }

    @RequiresPermissions("goldcoinaccount:goldcoinAccount:edit")
    @RequestMapping(value = "delete")
    public String delete(GoldcoinAccount goldcoinAccount, RedirectAttributes redirectAttributes) {
        goldcoinAccountService.delete(goldcoinAccount);
        addMessage(redirectAttributes, "删除金币账户成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinaccount/goldcoinAccount/?repage";
    }

}